def is_prime(b):

    flag = True

    for i in range(2, int(b)):

        c = int(b) % i

        if c == 0:

            flag = False

            break

    if flag:

        g.append(int(b))

a = input()

if len(a) == 4:

    print()

else:

    print("Число не четырехзначное")

    exit()

b0 = a [0]

b1 = a [1]

b2 = a [2]

b3 = a [3]

b4 = b0 + b1

b5 = b0 + b1 + b2

b6 = b1 + b2

b7 = b1 + b2 + b3

b8 = b2 + b3

g = []

is_prime(b0)

is_prime(b1)

is_prime(b2)

is_prime(b3)

is_prime(b4)

is_prime(b5)

is_prime(b6)

is_prime(b7)

is_prime(b8)

print(max(g))
